%画xvtf数据的函数
function [] = xvtf_fig(xvtf, lineStruct, qsStruct)
%% 待画数据提取
x_km = xvtf(:,1)./1000;
v_kmh = xvtf(:,2);
t_s = xvtf(:,3);
f_kN = xvtf(:,4);

%% 线路数据
grd_data = lineStruct.gradient;           
speedlimit = lineStruct.speedlimit;    
if qsStruct.pos_start > qsStruct.pos_end
    upordown = -1;
else
    upordown = 1;
end
%% 计算坡度
init_h = lineStruct.init_height;
h_(1) = init_h;
for j = 1:length(grd_data)
    h_(j+1) = h_(j) + (grd_data(j,2)-grd_data(j,1))*grd_data(j,3)/1000;
end
h_ = h_';
%% 处理限速数据
% 构造绘图数据
% 提取限速起点、终点和限速值
start_points = speedlimit(:, 1);
end_points = speedlimit(:, 2);
speed_values = speedlimit(:, 3);
vl_x = [];
vl_y = [];

for i = 1:size(speedlimit, 1)
    % 每段限速数据
    vl_x = [vl_x; start_points(i); end_points(i)];
    vl_y = [vl_y; speed_values(i); speed_values(i)];
end
vl_x = vl_x./1000; %m->km

%%
figure(10)
set(gcf,'Position',[100,100,800,800]);
[ha,pos] = tight_subplot(3, 1,[.01 .05],[.07 .05],[.08 .07]); % 缩小子图间距
axes(ha(1));
hl2 = plot(x_km,v_kmh,'LineWidth',2,'Color',[0 0.4470 0.7410]);
set(hl2, 'DisplayName', "实际速度")
hold on;
% hl3 = plot(new_mat(:,2),new_mat(:,8),'LineStyle',':','LineWidth',2.5,'Color',[0.8500 0.3250 0.0980]);
% set(hl3, 'DisplayName', "参考速度")
hl4 = plot(vl_x,vl_y,'LineStyle',':','LineWidth',1.5,'Color',	[1 0 1]);
set(hl4, 'DisplayName', "限速")
% xlim([min(new_mat(:,2))-0.2 max(new_mat(:,2))+0.2]);
% ylim([0 max(v_kmh)+20]);
xlabel("位置（km）");
ylabel("速度（km/h）");
if upordown == -1
    set(gca, 'XDir', 'reverse');
end
lgd = legend('show','Location','south');
axis([min(x_km)-0.2 max(x_km)+0.2 0 max(v_kmh)+20]);
% set(gca, 'XTickMode', 'auto', 'XTickLabelMode', 'auto');
% grid on;

% set(lgd, 'Position', [0, 0, 50, 60]); % 自定义位置
% title("空间域跟踪效果图");
axes(ha(2));
hl1 = area([grd_data(:,1);grd_data(end,2)]./1000,h_,'FaceColor',[0.7 0.7 0.7],'EdgeColor', [0.6 0.6 0.6],"FaceAlpha",0.35);
set(hl1, 'DisplayName', '坡度');
grid on;
legend("坡度")
xlim([min(x_km)-0.2 max(x_km)+0.2]);
ylim([min(h_)-50 max(h_)*1.5]);
ylabel("相对海拔（m）");
if upordown == -1
    set(gca, 'XDir', 'reverse');
end

axes(ha(3));
plot(x_km,f_kN,'LineWidth',2);
hold on;
% plot(new_mat(:,2),new_mat(:,5),'LineStyle',':','LineWidth',2.5);
% plot(new_mat(:,2),new_mat(:,7),'LineStyle','--','LineWidth',1.5);
plot([-1 1e6],[0 0],'LineStyle','--','Color',[0 0 0])
xlabel("位置（km）");
ylabel("力（kN）");
axis([min(x_km)-0.2 max(x_km)+0.2 min(f_kN)-50 max(f_kN)+50]);
if upordown == -1
    set(gca, 'XDir', 'reverse');
end
% grid on;
legend("实际力");